<?php
define("EW_PAGE_ID", "view", TRUE); // Page ID
define("EW_TABLE_NAME", 'tb_locations', TRUE);
?>
<?php 
session_start(); // Initialize session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg50.php" ?>
<?php include "ewmysql50.php" ?>
<?php include "phpfn50.php" ?>
<?php include "tb_locationsinfo.php" ?>
<?php include "userfn50.php" ?>
<?php include "tb_usersinfo.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Open connection to the database
$conn = ew_Connect();
?>
<?php
$Security = new cAdvancedSecurity();
?>
<?php
if (!$Security->IsLoggedIn()) $Security->AutoLogin();
if (!$Security->IsLoggedIn()) {
	$Security->SaveLastUrl();
	Page_Terminate("login.php");
}
?>
<?php

// Common page loading event (in userfn*.php)
Page_Loading();
?>
<?php

// Page load event, used in current page
Page_Load();
?>
<?php
$tb_locations->Export = @$_GET["export"]; // Get export parameter
$sExport = $tb_locations->Export; // Get export parameter, used in header
$sExportFile = $tb_locations->TableVar; // Get export file, used in header
?>
<?php
if (@$_GET["ID"] <> "") {
	$tb_locations->ID->setQueryStringValue($_GET["ID"]);
} else {
	Page_Terminate("tb_locationslist.php"); // Return to list page
}

// Get action
if (@$_POST["a_view"] <> "") {
	$tb_locations->CurrentAction = $_POST["a_view"];
} else {
	$tb_locations->CurrentAction = "I"; // Display form
}
switch ($tb_locations->CurrentAction) {
	case "I": // Get a record to display
		if (!LoadRow()) { // Load record based on key
			$_SESSION[EW_SESSION_MESSAGE] = "No records found"; // Set no record message
			Page_Terminate("tb_locationslist.php"); // Return to list
		}
}

// Set return url
$tb_locations->setReturnUrl("tb_locationsview.php");

// Render row
$tb_locations->RowType = EW_ROWTYPE_VIEW;
RenderRow();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--
var EW_PAGE_ID = "view"; // Page id

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<p><span class="phpmaker">View TABLE: Locations
<br><br>
<a href="tb_locationslist.php">Back to List</a>&nbsp;
<?php if ($Security->IsLoggedIn()) { ?>
<a href="tb_locationsadd.php">Add</a>&nbsp;
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<a href="<?php echo $tb_locations->EditUrl() ?>">Edit</a>&nbsp;
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<a href="<?php echo $tb_locations->CopyUrl() ?>">Copy</a>&nbsp;
<?php } ?>
<?php if ($Security->IsLoggedIn()) { ?>
<a href="<?php echo $tb_locations->DeleteUrl() ?>">Delete</a>&nbsp;
<?php } ?>
</span>
</p>
<?php
if (@$_SESSION[EW_SESSION_MESSAGE] <> "") {
?>
<p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
<?php
	$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message
}
?>
<p>
<form>
<table class="ewTable">
	<tr class="ewTableRow">
		<td class="ewTableHeader">ID</td>
		<td<?php echo $tb_locations->ID->CellAttributes() ?>>
<div<?php echo $tb_locations->ID->ViewAttributes() ?>><?php echo $tb_locations->ID->ViewValue ?></div>
</td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">Location Name</td>
		<td<?php echo $tb_locations->LocationName->CellAttributes() ?>>
<div<?php echo $tb_locations->LocationName->ViewAttributes() ?>><?php echo $tb_locations->LocationName->ViewValue ?></div>
</td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">Location Rent</td>
		<td<?php echo $tb_locations->LocationRent->CellAttributes() ?>>
<div<?php echo $tb_locations->LocationRent->ViewAttributes() ?>><?php echo $tb_locations->LocationRent->ViewValue ?></div>
</td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">Pay Roll</td>
		<td<?php echo $tb_locations->PayRoll->CellAttributes() ?>>
<div<?php echo $tb_locations->PayRoll->ViewAttributes() ?>><?php echo $tb_locations->PayRoll->ViewValue ?></div>
</td>
	</tr>
	<tr class="ewTableRow">
		<td class="ewTableHeader">Utilities</td>
		<td<?php echo $tb_locations->Utilities->CellAttributes() ?>>
<div<?php echo $tb_locations->Utilities->ViewAttributes() ?>><?php echo $tb_locations->Utilities->ViewValue ?></div>
</td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="ewTableHeader">Create Date</td>
		<td<?php echo $tb_locations->CreateDate->CellAttributes() ?>>
<div<?php echo $tb_locations->CreateDate->ViewAttributes() ?>><?php echo $tb_locations->CreateDate->ViewValue ?></div>
</td>
	</tr>
</table>
</form>
<p>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php

// If control is passed here, simply terminate the page without redirect
Page_Terminate();

// -----------------------------------------------------------------
//  Subroutine Page_Terminate
//  - called when exit page
//  - clean up connection and objects
//  - if url specified, redirect to url, otherwise end response
function Page_Terminate($url = "") {
	global $conn;

	// Page unload event, used in current page
	Page_Unload();

	// Global page unloaded event (in userfn*.php)
	Page_Unloaded();

	 // Close Connection
	$conn->Close();

	// Go to url if specified
	if ($url <> "") {
		ob_end_clean();
		header("Location: $url");
	}
	exit();
}
?>
<?php

// Load row based on key values
function LoadRow() {
	global $conn, $Security, $tb_locations;
	$sFilter = $tb_locations->SqlKeyFilter();
	if (!is_numeric($tb_locations->ID->CurrentValue)) {
		return FALSE; // Invalid key, exit
	}
	$sFilter = str_replace("@ID@", ew_AdjustSql($tb_locations->ID->CurrentValue), $sFilter); // Replace key value

	// Call Row Selecting event
	$tb_locations->Row_Selecting($sFilter);

	// Load sql based on filter
	$tb_locations->CurrentFilter = $sFilter;
	$sSql = $tb_locations->SQL();
	if ($rs = $conn->Execute($sSql)) {
		if ($rs->EOF) {
			$LoadRow = FALSE;
		} else {
			$LoadRow = TRUE;
			$rs->MoveFirst();
			LoadRowValues($rs); // Load row values

			// Call Row Selected event
			$tb_locations->Row_Selected($rs);
		}
		$rs->Close();
	} else {
		$LoadRow = FALSE;
	}
	return $LoadRow;
}

// Load row values from recordset
function LoadRowValues(&$rs) {
	global $tb_locations;
	$tb_locations->ID->setDbValue($rs->fields('ID'));
	$tb_locations->LocationName->setDbValue($rs->fields('LocationName'));
	$tb_locations->LocationRent->setDbValue($rs->fields('LocationRent'));
	$tb_locations->PayRoll->setDbValue($rs->fields('PayRoll'));
	$tb_locations->Utilities->setDbValue($rs->fields('Utilities'));
	$tb_locations->CreateDate->setDbValue($rs->fields('CreateDate'));
}
?>
<?php

// Render row values based on field settings
function RenderRow() {
	global $conn, $Security, $tb_locations;

	// Call Row Rendering event
	$tb_locations->Row_Rendering();

	// Common render codes for all row types
	// ID

	$tb_locations->ID->CellCssStyle = "";
	$tb_locations->ID->CellCssClass = "";

	// LocationName
	$tb_locations->LocationName->CellCssStyle = "";
	$tb_locations->LocationName->CellCssClass = "";

	// LocationRent
	$tb_locations->LocationRent->CellCssStyle = "";
	$tb_locations->LocationRent->CellCssClass = "";

	// PayRoll
	$tb_locations->PayRoll->CellCssStyle = "";
	$tb_locations->PayRoll->CellCssClass = "";

	// Utilities
	$tb_locations->Utilities->CellCssStyle = "";
	$tb_locations->Utilities->CellCssClass = "";

	// CreateDate
	$tb_locations->CreateDate->CellCssStyle = "";
	$tb_locations->CreateDate->CellCssClass = "";
	if ($tb_locations->RowType == EW_ROWTYPE_VIEW) { // View row

		// ID
		$tb_locations->ID->ViewValue = $tb_locations->ID->CurrentValue;
		$tb_locations->ID->CssStyle = "";
		$tb_locations->ID->CssClass = "";
		$tb_locations->ID->ViewCustomAttributes = "";

		// LocationName
		$tb_locations->LocationName->ViewValue = $tb_locations->LocationName->CurrentValue;
		$tb_locations->LocationName->CssStyle = "";
		$tb_locations->LocationName->CssClass = "";
		$tb_locations->LocationName->ViewCustomAttributes = "";

		// LocationRent
		$tb_locations->LocationRent->ViewValue = $tb_locations->LocationRent->CurrentValue;
		$tb_locations->LocationRent->ViewValue = ew_FormatCurrency($tb_locations->LocationRent->ViewValue, 2, -2, -2, 0);
		$tb_locations->LocationRent->CssStyle = "";
		$tb_locations->LocationRent->CssClass = "";
		$tb_locations->LocationRent->ViewCustomAttributes = "";

		// PayRoll
		$tb_locations->PayRoll->ViewValue = $tb_locations->PayRoll->CurrentValue;
		$tb_locations->PayRoll->ViewValue = ew_FormatCurrency($tb_locations->PayRoll->ViewValue, 2, -2, -2, -2);
		$tb_locations->PayRoll->CssStyle = "";
		$tb_locations->PayRoll->CssClass = "";
		$tb_locations->PayRoll->ViewCustomAttributes = "";

		// Utilities
		$tb_locations->Utilities->ViewValue = $tb_locations->Utilities->CurrentValue;
		$tb_locations->Utilities->ViewValue = ew_FormatCurrency($tb_locations->Utilities->ViewValue, 2, -2, -2, -2);
		$tb_locations->Utilities->CssStyle = "";
		$tb_locations->Utilities->CssClass = "";
		$tb_locations->Utilities->ViewCustomAttributes = "";

		// CreateDate
		$tb_locations->CreateDate->ViewValue = $tb_locations->CreateDate->CurrentValue;
		$tb_locations->CreateDate->ViewValue = ew_FormatDateTime($tb_locations->CreateDate->ViewValue, 10);
		$tb_locations->CreateDate->CssStyle = "";
		$tb_locations->CreateDate->CssClass = "";
		$tb_locations->CreateDate->ViewCustomAttributes = "";

		// ID
		$tb_locations->ID->HrefValue = "";

		// LocationName
		$tb_locations->LocationName->HrefValue = "";

		// LocationRent
		$tb_locations->LocationRent->HrefValue = "";

		// PayRoll
		$tb_locations->PayRoll->HrefValue = "";

		// Utilities
		$tb_locations->Utilities->HrefValue = "";

		// CreateDate
		$tb_locations->CreateDate->HrefValue = "";
	} elseif ($tb_locations->RowType == EW_ROWTYPE_ADD) { // Add row
	} elseif ($tb_locations->RowType == EW_ROWTYPE_EDIT) { // Edit row
	} elseif ($tb_locations->RowType == EW_ROWTYPE_SEARCH) { // Search row
	}

	// Call Row Rendered event
	$tb_locations->Row_Rendered();
}
?>
<?php

// Set up Starting Record parameters based on Pager Navigation
function SetUpStartRec() {
	global $nDisplayRecs, $nStartRec, $nTotalRecs, $nPageNo, $tb_locations;
	if ($nDisplayRecs == 0) return;

	// Check for a START parameter
	if (@$_GET[EW_TABLE_START_REC] <> "") {
		$nStartRec = $_GET[EW_TABLE_START_REC];
		$tb_locations->setStartRecordNumber($nStartRec);
	} elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
		$nPageNo = $_GET[EW_TABLE_PAGE_NO];
		if (is_numeric($nPageNo)) {
			$nStartRec = ($nPageNo-1)*$nDisplayRecs+1;
			if ($nStartRec <= 0) {
				$nStartRec = 1;
			} elseif ($nStartRec >= intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1) {
				$nStartRec = intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1;
			}
			$tb_locations->setStartRecordNumber($nStartRec);
		} else {
			$nStartRec = $tb_locations->getStartRecordNumber();
		}
	} else {
		$nStartRec = $tb_locations->getStartRecordNumber();
	}

	// Check if correct start record counter
	if (!is_numeric($nStartRec) || $nStartRec == "") { // Avoid invalid start record counter
		$nStartRec = 1; // Reset start record counter
		$tb_locations->setStartRecordNumber($nStartRec);
	} elseif (intval($nStartRec) > intval($nTotalRecs)) { // Avoid starting record > total records
		$nStartRec = intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1; // Point to last page first record
		$tb_locations->setStartRecordNumber($nStartRec);
	} elseif (($nStartRec-1) % $nDisplayRecs <> 0) {
		$nStartRec = intval(($nStartRec-1)/$nDisplayRecs)*$nDisplayRecs+1; // Point to page boundary
		$tb_locations->setStartRecordNumber($nStartRec);
	}
}
?>
<?php

// Page Load event
function Page_Load() {

	//echo "Page Load";
}

// Page Unload event
function Page_Unload() {

	//echo "Page Unload";
}
?>
